package cn.itcast.bos.service.auth.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.auth.FunctionDao;
import cn.itcast.bos.domain.auth.Function;
import cn.itcast.bos.domain.user.User;
import cn.itcast.bos.service.auth.FunctionService;

@Service("functionService")
@Transactional
public class FunctionServiceImpl implements FunctionService {

	@Autowired
	private FunctionDao functionDao;

	public List<Function> findAllFunctions() {
		// TODO Auto-generated method stub
		return functionDao.findAll();
	}

	public List<Function> findFucntionsByHasGenerateMenu() {
		// TODO Auto-generated method stub
		return functionDao.findFucntionsByHasGenerateMenu();
	}

	public List<Function> findFunctionsByUserId(User loginUser) {
		if ("admin".equals(loginUser.getUsername())) {
			return findAllFunctions();
		}
		// 非超级管理员
		return functionDao.findFunctionsByUserId(loginUser.getId());
	}

}
